/**
 * @Author yinyunqi
 * @date 2018年1月30日
 * @Content 
 */
package com.yongqi.service.back;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yongqi.mapper.FamilyMapper;
import com.yongqi.mapper.back.MessageMapper;
import com.yongqi.model.Family;
import com.yongqi.model.back.Message;

@Service
public class MessageService {
    @Autowired
    MessageMapper messageMapper;
    @Autowired
    FamilyMapper familyMapper;
    public List<Message> msgTest(Map<String, String> map){
	return messageMapper.msgTest(map);
    }
    /**
     * 首页推送消息
     * @param map
     * @return
     */
    public List<Message> msgPushQuery(Map<String, String> map){
	return messageMapper.msgPushQuery(map);
    }
    public List<Message> msgQuery(Map<String, String> map){
    	return messageMapper.msgQuery(map);
        }
    /**
     * 后台-消息推送管理查询
     * @param map
     * @return
     */
    public List<Message> backMsgQuery(Map<String, String> map){
	return messageMapper.backMsgQuery(map);
    } 
    /**
     * 后台-消息推送管理详细查询
     * @param map
     * @return
     */
    public List<Message> backMsgQueryById(Map<String, String> map){
	return messageMapper.backMsgQueryById(map);
    } 
    /**
     * 后台-消息推送管理按ID删除
     * @param map
     * @return
     */
    public void backMsgDetele(Map<String, String> map){
	messageMapper.backMsgDetele(map);
    } 
    public void changeReaded(Map<String, String> map) {
    	messageMapper.changeReaded(map);
    }
    /**
     * 后台-消息推送管理发送推送
     * @param message
     */
    public void backMsgPushSend(Message message) {
	if(message.getReciver().equals("all")) {
	    //所有人，遍历用户
	    
	   Map<String, String> map = new HashMap<String, String>();
	   List<Family> familyList = familyMapper.backFamilyQuery(map);
	   for (Family family : familyList) {
	       message.setReciver(family.getFamilyaccount());
	       message.setId(UUID.randomUUID().toString());
	       messageMapper.backMsgPushSend(message);
	   }
	}else{
	    //单个用户
	    message.setId(UUID.randomUUID().toString());
	    messageMapper.backMsgPushSend(message);
	}
    }
}

